package system.task.logger;

import system.task.Task;
import system.task.logger.buffer.TaskLogBufferAdmin;

public class TaskLoggerBufferWriter implements TaskLoggerWriter {

    private final Task task;
    private final String runId;
    private final int maxLine;

    public TaskLoggerBufferWriter(Task task, String runId, int maxLine) {
        this.task = task;
        this.runId = runId;
        this.maxLine = maxLine;
    }

    @Override
    public void close() throws Exception {

    }

    @Override
    public void info(String time, String message, boolean newLine) {
        StringBuilder builder = TaskLoggerUtil.buildContent(time, message, newLine);
        TaskLogBufferAdmin.instance.log(this.maxLine, this.task.getName(), runId, builder.toString());
    }

    @Override
    public void error(String time, String message, boolean newLine) {
        StringBuilder builder = TaskLoggerUtil.buildError(time, message, newLine);
        TaskLogBufferAdmin.instance.log(this.maxLine, this.task.getName(), runId, builder.toString());
    }
}
